package com.androidgame.fx;

import android.graphics.Color;
import android.graphics.Typeface;

public class GameTime {

	private long 	worldTime;
	private long 	tempWorldTime;
	private long 	frame;
	private long 	fps;
	private long 	framePerSec;
	private long 	lastTime;
	private Typeface gameFont;

	public GameTime() {
		lastTime = System.currentTimeMillis();
		worldTime = 0;

		gameFont = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
	}
	
	public void reset() {
		lastTime = System.currentTimeMillis();
		worldTime = 0;
	}

	public void update() {
		frame++;
		long currentTime = System.currentTimeMillis();
		long elapsedTime = currentTime - lastTime;
		worldTime += elapsedTime;
		lastTime = currentTime;

		if (tempWorldTime < worldTime) {
			tempWorldTime = worldTime + 1000;
			fps = framePerSec;
			framePerSec = 0;
		} else {
			framePerSec++;
		}
	}

	public void present(Graphics g) {
		g.drawText("GAME TIME : " + worldTime, 30, 30, Color.WHITE, 30, gameFont);
		g.drawText("FPS : " + fps, 30, 60, Color.WHITE, 30, gameFont);
	}
	
	public long getWorldTime() {
		return worldTime;
	}
}
